package com.tjetc.controller;


import com.tjetc.entity.Result;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class UserController {

    // 支持远程调用 通过httpclient调用
    @Resource
    private RestTemplate restTemplate;

    // 远程调用服务的基础地址
//    private static final String USER_SERVICE_PROVIDER_URL = "http://localhost:11000";
//    private static final String USER_SERVICE_PROVIDER_URL = "http://USER-SERVICE-PROVIDER-11000";
    private static final String USER_SERVICE_PROVIDER_URL = "http://USER-SERVICE-PROVIDER";


    @GetMapping("/user/consumer/get/{id}")
    public Result getUserById(@PathVariable("id") int id) {
        System.out.println(id);
        // 在执行调用的时候 请求的地址为 http://localhost:10000/user/get/1
        return restTemplate.getForObject(USER_SERVICE_PROVIDER_URL + "/user/get/" + id, Result.class);
    }

}
